import User from "../model/user.model.js";

class UserService {
  async createUser(user_name, password, isAdmain) {
    const res = await User.create({ user_name, password, isAdmain });
    return res.dataValues;
  }

  async getUerInfo({ id, user_name, password, isAdmain }) {
    const whereOpt = {};

    id && Object.assign(whereOpt, { id });
    user_name && Object.assign(whereOpt, { user_name });
    password && Object.assign(whereOpt, { password });
    isAdmain && Object.assign(whereOpt, { isAdmain });

    const res = await User.findOne({
      attributes: ["id", "user_name", "password", "isAdmain"],
      where: whereOpt,
    });

    return res;
  }
}

export default new UserService();
